package com.cdut.controller;


import com.cdut.domain.House;
import com.cdut.domain.Info;
import com.cdut.domain.Message;
import com.cdut.service.impl.HouseServiceImpl;
import jdk.internal.dynalink.linker.LinkerServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@CrossOrigin
@RequestMapping("api/house/")
public class HouseController {
    @Autowired(required = false)
    HouseServiceImpl houseService;
    Message message;
    Info info;


    @GetMapping("findAll")
    public  Message findAll(){
        try{
            message = new Message();
            message.setData(houseService.findAll());
            info =new Info();
            info.success();
            message.setInfo(info);
            return message;
        }
        catch (Exception exception){
            message = new  Message();
            info =new Info();
            info.fail();
            message.setInfo(info);
            return message;
        }
    }

    /*
    统计year
     */
    @GetMapping("countYear")
    public  Message countYear(){
        try{
            message = new Message();
            message.setData(houseService.countYear());
            info =new Info();
            info.success();
            message.setInfo(info);
            return message;
        }
        catch (Exception exception){
            System.out.println(exception);
            message = new  Message();
            info =new Info();
            info.fail();
            message.setInfo(info);
            return message;
        }
    }

    /*
            分析地区和价格的关系
             */
    @GetMapping("region_price")
    public  Message region_price(){
        try{
            message = new Message();
            message.setData(houseService.region_price());
            info =new Info();
            info.success();
            message.setInfo(info);
            return message;
        }
        catch (Exception exception){
            System.out.println(exception);
            message = new  Message();
            info =new Info();
            info.fail();
            message.setInfo(info);
            return message;
        }
    }

    /*

      分析年份和价格的关系
    */

    @GetMapping("year_price")
    public  Message year_price(){
        try{
            message = new Message();
            message.setData(houseService.year_price());
            info =new Info();
            info.success();
            message.setInfo(info);
            return message;
        }
        catch (Exception exception){
            System.out.println(exception);
            message = new  Message();
            info =new Info();
            info.fail();
            message.setInfo(info);
            return message;
        }
    }

    /*
               不同类型房屋数量
                */
    @GetMapping("house_type")
    public  Message house_type(){
        try{
            message = new Message();
            message.setData(houseService.house_type());
            info =new Info();
            info.success();
            message.setInfo(info);
            return message;
        }
        catch (Exception exception){
            System.out.println(exception);
            message = new  Message();
            info =new Info();
            info.fail();
            message.setInfo(info);
            return message;
        }
    }

    /*
                   每个行政区的建筑数量
                    */
    @GetMapping("region_buildings_num")
    public  Message region_buildings_num(){
        try{
            message = new Message();
            message.setData(houseService.region_buildings_num());
            info =new Info();
            info.success();
            message.setInfo(info);
            return message;
        }
        catch (Exception exception){
            System.out.println(exception);
            message = new  Message();
            info =new Info();
            info.fail();
            message.setInfo(info);
            return message;
        }
    }

    /*
                  不同地区房屋数量
                   */
    @GetMapping("area_number")
    public  Message area_number(){
        try{
            message = new Message();
            message.setData(houseService.area_number());
            info =new Info();
            info.success();
            message.setInfo(info);
            return message;
        }
        catch (Exception exception){
            System.out.println(exception);
            message = new  Message();
            info =new Info();
            info.fail();
            message.setInfo(info);
            return message;
        }
    }

    /*
                  不同地区的房屋平均价格
                   */
    @GetMapping("area_price")
    public  Message area_price(){
        try{
            message = new Message();
            message.setData(houseService.area_price());
            info =new Info();
            info.success();
            message.setInfo(info);
            return message;
        }
        catch (Exception exception){
            System.out.println(exception);
            message = new  Message();
            info =new Info();
            info.fail();
            message.setInfo(info);
            return message;
        }
    }


    /*
          不同行政区的住宅数（人口密度)
                   */
    @GetMapping("region_households_num")
    public  Message region_households_num(){
        try{
            message = new Message();
            message.setData(houseService.region_households_num());
            info =new Info();
            info.success();
            message.setInfo(info);
            return message;
        }
        catch (Exception exception){
            System.out.println(exception);
            message = new  Message();
            info =new Info();
            info.fail();
            message.setInfo(info);
            return message;
        }
    }

    /*
          最近5年内不同地区的平均价格
                   */
    @GetMapping("year_reg_price")
    public  Message year_reg_price(){
        try{
            message = new Message();
            message.setData(houseService.year_reg_price());
            info =new Info();
            info.success();
            message.setInfo(info);
            return message;
        }
        catch (Exception exception){
            System.out.println(exception);
            message = new  Message();
            info =new Info();
            info.fail();
            message.setInfo(info);
            return message;
        }
    }

    /*
          排行榜
                   */
    @GetMapping("rank")
    public  Message rank(){
        try{
            message = new Message();
            message.setData(houseService.rank());
            info =new Info();
            info.success();
            message.setInfo(info);
            return message;
        }
        catch (Exception exception){
            System.out.println(exception);
            message = new  Message();
            info =new Info();
            info.fail();
            message.setInfo(info);
            return message;
        }
    }


    /*

      房屋在09年到18年修建的平均价格  （上海）
    */

    @GetMapping("year_price_sh")
    public  Message year_price_sh(){
        try{
            message = new Message();
            message.setData(houseService.year_price_sh());
            info =new Info();
            info.success();
            message.setInfo(info);
            return message;
        }
        catch (Exception exception){
            System.out.println(exception);
            message = new  Message();
            info =new Info();
            info.fail();
            message.setInfo(info);
            return message;
        }
    }

    /*

      房屋在09年到18年修建的平均价格  （上海）
    */

    @GetMapping("year_price_cd")
    public  Message year_price_cd(){
        try{
            message = new Message();
            message.setData(houseService.year_price_cd());
            info =new Info();
            info.success();
            message.setInfo(info);
            return message;
        }
        catch (Exception exception){
            System.out.println(exception);
            message = new  Message();
            info =new Info();
            info.fail();
            message.setInfo(info);
            return message;
        }
    }

}
